package br.com.usjt.locadoraweb.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import br.com.usjt.locadoraweb.model.AcessoBD;
import br.com.usjt.locadoraweb.model.ClientPF;

public class ClientPFDAO {
	boolean status = false;

	public boolean includeClient (ClientPF clientPF) {
		
		String sqlIncludeClientPF =
				"INSERT INTO clientpf (" 		+
						"id,"					+
						"name," 				+
						"cpf," 					+
						"rg," 					+
						"birthDate,"			+
						"sex,"					+
						"address,"				+
						"phone,"				+
						"email,"				+
						"cnh,"					+
						"category,"				+
						"ufIssue,"				+
						"validityCnh"			+
						") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
		
		PreparedStatement stm = null;
		Connection conn = null;
		
		try {
			int id = 0;
			AcessoBD bd = new AcessoBD();
			conn = bd.obtemConexao();
			
			stm = conn.prepareStatement(sqlIncludeClientPF);
			System.out.println(id);
			
			stm.setLong(1, bd.obterProximoIdentificador("clientpf"));
			stm.setString(2, clientPF.getName());
			stm.setString(3, clientPF.getCpf());
			stm.setString(4, clientPF.getRg());
			stm.setString(5, clientPF.getBirthDate());
			stm.setString(6, clientPF.getSex());
			stm.setString(7, clientPF.getAddress());
			stm.setString(8, clientPF.getPhone());
			stm.setString(9, clientPF.getEmail());
			stm.setString(10, clientPF.getCnh());
			stm.setString(11, clientPF.getCategory());
			stm.setString(12, clientPF.getUfIssue());
			stm.setString(13, clientPF.getValidityCnh());

			stm.execute();
			status = true;
			
		} catch (Exception e) {
				e.printStackTrace();
				
			} finally {
				if (stm != null) {
					try {
						stm.close();
					} catch (SQLException e1) {
						System.out.print(e1.getStackTrace());
					}
				}
			}
		return status;
	}

}

